// 监控函数 输出结果
// interface: ens192
// IP address is: 192.168.101.242
// MAC address is: 00:0c:29:64:57:d4
// Jaina 0% 5341MB/32012MB 16.68% 41G/45G 91% 6.80Kb/s D 5.66Kb/s U Jaina
function websshMonitor() {
    $.post(
        "http://127.0.0.1:1111/main", {
            "cmd":"startMonitor",
            "ip":ip,
            "user":user,
            "name":name,
            "monitor":'history -w ; memuse=$(free -m | sed -n \'2p\' | awk \'{print $3}\') ; memall=$(free -m | sed -n \'2p\' | awk \'{print $2}\') ; freerate=$(echo $memuse $memall |awk \'{printf ("%.2f\\n",($1/$2)*100)}\') ; cpurate=$(vmstat -w 2 2 | sed -n \'4p\' | awk -F \' \' \'{print $13,$14}\' | awk \'{print $1+$2}\' ) ; diskrate=$(df -hT | grep -w "/" | awk \'{print $6}\' | sed \'s/%//g\') ; diskall=$(df -hT | grep -w "/" | awk \'{print $3}\' | sed \'s/%//g\') ; diskuse=$(df -hT | grep -w "/" | awk \'{print $4}\' | sed \'s/%//g\') ; netall=$(/usr/sbin/iftop -t -s 3 | grep Total | awk \'{print $(NF-2)}\') ; netsend=$(echo $netall | awk \'{print $1}\') ; netreceive=$(echo $netall | awk \'{print $2}\') ; echo Jaina $(date +"%D-%T") ${cpurate}% ${memuse}MB/${memall}MB ${freerate}% ${diskuse}/${diskall} ${diskrate}% ${netreceive}/s D ${netsend}/s U Jaina ; history -c' + "\r",
            "size":100,"timeout":7200
        },function (data) {
            // console.info("监控消息：" + data)
            splitData = data.split(" ");
            cpu = splitData[2]
            mem = splitData[3]
            disk = splitData[5]
            down = splitData[7]
            up = splitData[9]

            redEnd = '</font>'
            cpu.split("%")[0] >= 90 ? redCPU = '<font color="#FF0000">' : redCPU = '<font>'
            mem.split("/")[0].split("MB")[0] >=  mem.split("/")[1].split("MB")[0] * 0.9 ? redMem = '<font color="#FF0000">' : redMem = '<font>'
            disk.split("/")[0].split("G")[0] >=  disk.split("/")[1].split("G")[0] * 0.9 ? redDisk = '<font color="#FF0000">' : redDisk = '<font>'

            $("#sshMonitor").html(function(){
                return  '<img class="monitor" alt="cpuMonitor" src="img/websshMonitorCPU.png" />' + redCPU + cpu + redEnd  + '&nbsp;&nbsp;' +
                    '<img class="monitor" alt="memMonitor" src="img/websshMonitorMem.png" />' + redMem + mem +　redEnd　+ '&nbsp;&nbsp;' +
                    '<img class="monitor" alt="diskMonitor" src="img/websshMonitorDisk.png" />' + redDisk + disk + redEnd + '&nbsp;&nbsp;' +
                    '<img class="monitor" alt="upMonitor" src="img/websshMonitorUp.png" />' + up + '&nbsp;&nbsp;' +
                    '<img class="monitor" alt="downMonitor" src="img/websshMonitorDown.png" />' + down;
            })
        });
}